// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file arrays_and_sequencesTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include "arrays_and_sequencesTypeObjectSupport.hpp"

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include "arrays_and_sequences.hpp"


using namespace eprosima::fastdds::dds::xtypes;

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_AnInternalObject_type_identifier(
        TypeIdentifierPair& type_ids_AnInternalObject)
{

    ReturnCode_t return_code_AnInternalObject {eprosima::fastdds::dds::RETCODE_OK};
    return_code_AnInternalObject =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "AnInternalObject", type_ids_AnInternalObject);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_AnInternalObject)
    {
        StructTypeFlag struct_flags_AnInternalObject = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_AnInternalObject = "AnInternalObject";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_AnInternalObject;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_AnInternalObject;
        CompleteTypeDetail detail_AnInternalObject = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_AnInternalObject, ann_custom_AnInternalObject, type_name_AnInternalObject.to_string());
        CompleteStructHeader header_AnInternalObject;
        header_AnInternalObject = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_AnInternalObject);
        CompleteStructMemberSeq member_seq_AnInternalObject;
        {
            TypeIdentifierPair type_ids_x;
            ReturnCode_t return_code_x {eprosima::fastdds::dds::RETCODE_OK};
            return_code_x =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_float", type_ids_x);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_x)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "x Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_x = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_x = 0x00000000;
            bool common_x_ec {false};
            CommonStructMember common_x {TypeObjectUtils::build_common_struct_member(member_id_x, member_flags_x, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_x, common_x_ec))};
            if (!common_x_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure x member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_x = "x";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_x;
            ann_custom_AnInternalObject.reset();
            CompleteMemberDetail detail_x = TypeObjectUtils::build_complete_member_detail(name_x, member_ann_builtin_x, ann_custom_AnInternalObject);
            CompleteStructMember member_x = TypeObjectUtils::build_complete_struct_member(common_x, detail_x);
            TypeObjectUtils::add_complete_struct_member(member_seq_AnInternalObject, member_x);
        }
        {
            TypeIdentifierPair type_ids_positive;
            ReturnCode_t return_code_positive {eprosima::fastdds::dds::RETCODE_OK};
            return_code_positive =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_bool", type_ids_positive);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_positive)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "positive Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_positive = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_positive = 0x00000001;
            bool common_positive_ec {false};
            CommonStructMember common_positive {TypeObjectUtils::build_common_struct_member(member_id_positive, member_flags_positive, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_positive, common_positive_ec))};
            if (!common_positive_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure positive member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_positive = "positive";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_positive;
            ann_custom_AnInternalObject.reset();
            CompleteMemberDetail detail_positive = TypeObjectUtils::build_complete_member_detail(name_positive, member_ann_builtin_positive, ann_custom_AnInternalObject);
            CompleteStructMember member_positive = TypeObjectUtils::build_complete_struct_member(common_positive, detail_positive);
            TypeObjectUtils::add_complete_struct_member(member_seq_AnInternalObject, member_positive);
        }
        CompleteStructType struct_type_AnInternalObject = TypeObjectUtils::build_complete_struct_type(struct_flags_AnInternalObject, header_AnInternalObject, member_seq_AnInternalObject);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_AnInternalObject, type_name_AnInternalObject.to_string(), type_ids_AnInternalObject))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "AnInternalObject already registered in TypeObjectRegistry for a different type.");
        }
    }
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_arrays_and_sequences_type_identifier(
        TypeIdentifierPair& type_ids_arrays_and_sequences)
{

    ReturnCode_t return_code_arrays_and_sequences {eprosima::fastdds::dds::RETCODE_OK};
    return_code_arrays_and_sequences =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "arrays_and_sequences", type_ids_arrays_and_sequences);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_arrays_and_sequences)
    {
        StructTypeFlag struct_flags_arrays_and_sequences = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_arrays_and_sequences = "arrays_and_sequences";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_arrays_and_sequences;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_arrays_and_sequences;
        CompleteTypeDetail detail_arrays_and_sequences = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_arrays_and_sequences, ann_custom_arrays_and_sequences, type_name_arrays_and_sequences.to_string());
        CompleteStructHeader header_arrays_and_sequences;
        header_arrays_and_sequences = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_arrays_and_sequences);
        CompleteStructMemberSeq member_seq_arrays_and_sequences;
        {
            TypeIdentifierPair type_ids_unlimited_vector;
            ReturnCode_t return_code_unlimited_vector {eprosima::fastdds::dds::RETCODE_OK};
            return_code_unlimited_vector =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_sequence_AnInternalObject_unbounded", type_ids_unlimited_vector);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_unlimited_vector)
            {
                return_code_unlimited_vector =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "AnInternalObject", type_ids_unlimited_vector);

                if (eprosima::fastdds::dds::RETCODE_OK != return_code_unlimited_vector)
                {
                ::register_AnInternalObject_type_identifier(type_ids_unlimited_vector);
                }
                bool element_identifier_anonymous_sequence_AnInternalObject_unbounded_ec {false};
                TypeIdentifier* element_identifier_anonymous_sequence_AnInternalObject_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_unlimited_vector, element_identifier_anonymous_sequence_AnInternalObject_unbounded_ec))};
                if (!element_identifier_anonymous_sequence_AnInternalObject_unbounded_ec)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
                    return;
                }
                EquivalenceKind equiv_kind_anonymous_sequence_AnInternalObject_unbounded = EK_COMPLETE;
                if (TK_NONE == type_ids_unlimited_vector.type_identifier2()._d())
                {
                    equiv_kind_anonymous_sequence_AnInternalObject_unbounded = EK_BOTH;
                }
                CollectionElementFlag element_flags_anonymous_sequence_AnInternalObject_unbounded = 0;
                PlainCollectionHeader header_anonymous_sequence_AnInternalObject_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_AnInternalObject_unbounded, element_flags_anonymous_sequence_AnInternalObject_unbounded);
                {
                    SBound bound = 0;
                    PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_AnInternalObject_unbounded, bound,
                                eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_AnInternalObject_unbounded));
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_AnInternalObject_unbounded", type_ids_unlimited_vector))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_sequence_AnInternalObject_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_unlimited_vector = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_unlimited_vector = 0x00000000;
            bool common_unlimited_vector_ec {false};
            CommonStructMember common_unlimited_vector {TypeObjectUtils::build_common_struct_member(member_id_unlimited_vector, member_flags_unlimited_vector, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_unlimited_vector, common_unlimited_vector_ec))};
            if (!common_unlimited_vector_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure unlimited_vector member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_unlimited_vector = "unlimited_vector";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_unlimited_vector;
            ann_custom_arrays_and_sequences.reset();
            CompleteMemberDetail detail_unlimited_vector = TypeObjectUtils::build_complete_member_detail(name_unlimited_vector, member_ann_builtin_unlimited_vector, ann_custom_arrays_and_sequences);
            CompleteStructMember member_unlimited_vector = TypeObjectUtils::build_complete_struct_member(common_unlimited_vector, detail_unlimited_vector);
            TypeObjectUtils::add_complete_struct_member(member_seq_arrays_and_sequences, member_unlimited_vector);
        }
        {
            TypeIdentifierPair type_ids_limited_vector;
            ReturnCode_t return_code_limited_vector {eprosima::fastdds::dds::RETCODE_OK};
            return_code_limited_vector =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_sequence_AnInternalObject_10", type_ids_limited_vector);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_limited_vector)
            {
                return_code_limited_vector =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "AnInternalObject", type_ids_limited_vector);

                if (eprosima::fastdds::dds::RETCODE_OK != return_code_limited_vector)
                {
                ::register_AnInternalObject_type_identifier(type_ids_limited_vector);
                }
                bool element_identifier_anonymous_sequence_AnInternalObject_10_ec {false};
                TypeIdentifier* element_identifier_anonymous_sequence_AnInternalObject_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_limited_vector, element_identifier_anonymous_sequence_AnInternalObject_10_ec))};
                if (!element_identifier_anonymous_sequence_AnInternalObject_10_ec)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
                    return;
                }
                EquivalenceKind equiv_kind_anonymous_sequence_AnInternalObject_10 = EK_COMPLETE;
                if (TK_NONE == type_ids_limited_vector.type_identifier2()._d())
                {
                    equiv_kind_anonymous_sequence_AnInternalObject_10 = EK_BOTH;
                }
                CollectionElementFlag element_flags_anonymous_sequence_AnInternalObject_10 = 0;
                PlainCollectionHeader header_anonymous_sequence_AnInternalObject_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_AnInternalObject_10, element_flags_anonymous_sequence_AnInternalObject_10);
                {
                    SBound bound = static_cast<SBound>(10);
                    PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_AnInternalObject_10, bound,
                                eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_AnInternalObject_10));
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_AnInternalObject_10", type_ids_limited_vector))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_sequence_AnInternalObject_10 already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_limited_vector = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_limited_vector = 0x00000001;
            bool common_limited_vector_ec {false};
            CommonStructMember common_limited_vector {TypeObjectUtils::build_common_struct_member(member_id_limited_vector, member_flags_limited_vector, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_limited_vector, common_limited_vector_ec))};
            if (!common_limited_vector_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure limited_vector member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_limited_vector = "limited_vector";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_limited_vector;
            ann_custom_arrays_and_sequences.reset();
            CompleteMemberDetail detail_limited_vector = TypeObjectUtils::build_complete_member_detail(name_limited_vector, member_ann_builtin_limited_vector, ann_custom_arrays_and_sequences);
            CompleteStructMember member_limited_vector = TypeObjectUtils::build_complete_struct_member(common_limited_vector, detail_limited_vector);
            TypeObjectUtils::add_complete_struct_member(member_seq_arrays_and_sequences, member_limited_vector);
        }
        {
            TypeIdentifierPair type_ids_limited_array;
            ReturnCode_t return_code_limited_array {eprosima::fastdds::dds::RETCODE_OK};
            return_code_limited_array =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_array_AnInternalObject_10", type_ids_limited_array);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_limited_array)
            {
                return_code_limited_array =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "AnInternalObject", type_ids_limited_array);

                if (eprosima::fastdds::dds::RETCODE_OK != return_code_limited_array)
                {
                ::register_AnInternalObject_type_identifier(type_ids_limited_array);
                }
                bool element_identifier_anonymous_array_AnInternalObject_10_ec {false};
                TypeIdentifier* element_identifier_anonymous_array_AnInternalObject_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_limited_array, element_identifier_anonymous_array_AnInternalObject_10_ec))};
                if (!element_identifier_anonymous_array_AnInternalObject_10_ec)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent.");
                    return;
                }
                EquivalenceKind equiv_kind_anonymous_array_AnInternalObject_10 = EK_COMPLETE;
                if (TK_NONE == type_ids_limited_array.type_identifier2()._d())
                {
                    equiv_kind_anonymous_array_AnInternalObject_10 = EK_BOTH;
                }
                CollectionElementFlag element_flags_anonymous_array_AnInternalObject_10 = 0;
                PlainCollectionHeader header_anonymous_array_AnInternalObject_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_AnInternalObject_10, element_flags_anonymous_array_AnInternalObject_10);
                {
                    SBoundSeq array_bound_seq;
                        TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast<SBound>(10));

                    PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_AnInternalObject_10, array_bound_seq,
                                eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_array_AnInternalObject_10));
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_AnInternalObject_10", type_ids_limited_array))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_array_AnInternalObject_10 already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_limited_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_limited_array = 0x00000002;
            bool common_limited_array_ec {false};
            CommonStructMember common_limited_array {TypeObjectUtils::build_common_struct_member(member_id_limited_array, member_flags_limited_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_limited_array, common_limited_array_ec))};
            if (!common_limited_array_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure limited_array member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_limited_array = "limited_array";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_limited_array;
            ann_custom_arrays_and_sequences.reset();
            CompleteMemberDetail detail_limited_array = TypeObjectUtils::build_complete_member_detail(name_limited_array, member_ann_builtin_limited_array, ann_custom_arrays_and_sequences);
            CompleteStructMember member_limited_array = TypeObjectUtils::build_complete_struct_member(common_limited_array, detail_limited_array);
            TypeObjectUtils::add_complete_struct_member(member_seq_arrays_and_sequences, member_limited_array);
        }
        CompleteStructType struct_type_arrays_and_sequences = TypeObjectUtils::build_complete_struct_type(struct_flags_arrays_and_sequences, header_arrays_and_sequences, member_seq_arrays_and_sequences);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_arrays_and_sequences, type_name_arrays_and_sequences.to_string(), type_ids_arrays_and_sequences))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "arrays_and_sequences already registered in TypeObjectRegistry for a different type.");
        }
    }
}

